package com.hfzy.ihk.web.linkcall.context;


import com.hfzy.ihk.web.linkcall.conf.PublicConfig;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * 语音功能初始化类
 * */
@Component
public class SpeechFunctionInitBean implements InitializingBean {

    public static ExecutorService speechSynthesizerExecutor;//语音合成处理线程数
    public static ExecutorService speechTranscribeExecutor;//语音识别处理线程数
    public static RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy(); //线程池策略如果队列满了就用当前线程去执行

    @Override
    public void afterPropertiesSet() throws Exception {
        int speechSynthesizerhandlerSize = PublicConfig.SPEECH_SYNTHESIZER_THREAD_POOL_SIZE;
        int speechTranscribehandlerSize = PublicConfig.SPEECH_TRANSCRIBE_THREAD_POOL_SIZE;

        SpeechFunctionInitBean.setSpeechSynthesizerExecutor(new ThreadPoolExecutor(5, 5, 0, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(100),handler));
        SpeechFunctionInitBean.setSpeechTranscribeExecutor(new ThreadPoolExecutor(5, 5, 0, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(100),handler));
    }


    public static ExecutorService getSpeechSynthesizerExecutor() {
        return speechSynthesizerExecutor;
    }

    public static void setSpeechSynthesizerExecutor(ExecutorService speechSynthesizerExecutor) {
        SpeechFunctionInitBean.speechSynthesizerExecutor = speechSynthesizerExecutor;
    }

    public static ExecutorService getSpeechTranscribeExecutor() {
        return speechTranscribeExecutor;
    }

    public static void setSpeechTranscribeExecutor(ExecutorService speechTranscribeExecutor) {
        SpeechFunctionInitBean.speechTranscribeExecutor = speechTranscribeExecutor;
    }
}
